<?php
namespace app\common\model\user;

use think\Model;

class Receive extends  Model{

    protected $name = 'user_reward_receive';

    public function getList($params){
        $filter = [];
        !empty($params['nickName']) && $filter['u.nickName|w.name|l.name'] = ['like', '%' . trim($params['nickName']) . '%'];
        $list= $this->alias('ur')->order([ 'receive_time' => 'desc'])
            ->where($filter)
            ->join('user_label_reward w','ur.reward_id=w.reward_id')
            ->join('user_label l','ur.label_id=l.label_id')
            ->join('user u','ur.user_id=u.user_id')
            ->field('ur.*,w.name,l.name as label_name,u.nickName,u.avatarUrl,u.address_id,u.user_label_id')
            ->paginate(15, false, [
                'query' => request()->request()
            ]);
        return $list;
    }


    public function getReceived($reward_id,$user_id){
        $id=$this->where(['reward_id'=>$reward_id,'user_id'=>$user_id])->value('id');
        return $id;
    }
    /**
     * 新增记录
     * @param $data
     * @return false|int
     */
    public function add($data)
    {

        return $this->allowField(true)->save($data);
    }

    public  function detail($id)
    {
        $data=$this->alias('ur')->where(['id'=>$id])
            ->join('user_label_reward w','ur.reward_id=w.reward_id')
            ->join('user_label l','ur.label_id=l.label_id')
            ->join('user u','ur.user_id=u.user_id')

            ->field('ur.*,w.name,l.name as label_name,u.nickName,u.avatarUrl,u.user_label_id')

            ->find();
        return $data;
    }


}